package com.foreveross.proxyip.web.action.pools;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.dayatang.domain.InstanceFactory;
import com.foreveross.proxyip.application.pool.ApplyIpLogApplication;
import com.foreveross.proxyip.application.pool.vo.ApplyIpLogVo;
import com.foreveross.proxyip.core.pools.PoolsManager;
import com.foreveross.proxyip.entity.ChannelEntity;
import com.foreveross.proxyip.exception.ProxyIpServiceException;
import com.foreveross.proxyip.infra.PageData;
import com.foreveross.proxyip.web.action.BaseAction;

@SuppressWarnings("serial")
@Controller
@org.springframework.context.annotation.Scope("prototype")
@Namespace("/pools/applyIpLog")
@ParentPackage("json-default")
public class ApplyIpLogAction  extends BaseAction {
	@Autowired 
	ApplyIpLogApplication application;

	PageData pageData = new PageData();
	
	ApplyIpLogVo vo = new ApplyIpLogVo();

	private Integer pageIndex;

	private Integer pageLen;
	
	@Action(value="toJsp",results={@Result(name="dispatcher", type="dispatcher",location="/pools/applyIpLog.jsp")})
	public String toJsp()throws ProxyIpServiceException{
		loadChannels();
		return "dispatcher";
	}
	
	/**
	 * 检索（按某些条件）
	 * @return
	 */
	@Action(value="search", results={@Result(name="JSON", type="json", params={"root","pageData"})})
	public String search()throws Exception{
		//页面加载好pageData.PageIndex ,pageData.PageLen
//		pageData.setPageIndex(pageIndex);
//		pageData.setPageLen(pageLen);
		pageData = application.searchByConditions(vo, pageIndex, pageLen);
//				application.loadPageData(vo,pageData);
//				initPublicPoolVo();
		return "JSON";
	}

	private void loadChannels(){
		PoolsManager poolsManager = InstanceFactory
		.getInstance(PoolsManager.class);
		List<ChannelEntity> channels = poolsManager.getChannelEntitys();
		vo.setChannels(channels);
	}
	

	public PageData getPageData() {
		return pageData;
	}

	public void setPageData(PageData pageData) {
		this.pageData = pageData;
	}

	public ApplyIpLogVo getVo() {
		return vo;
	}

	public void setVo(ApplyIpLogVo vo) {
		this.vo = vo;
	}

	public Integer getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}

	public Integer getPageLen() {
		return pageLen;
	}

	public void setPageLen(Integer pageLen) {
		this.pageLen = pageLen;
	}
}
